﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Text;
using Zj.HttpCodeDemo.Domain.Entities;
using Zj.HttpCodeDemo.Repository.Models.Mappings;

namespace Zj.HttpCodeDemo.Repository.Models
{
    public class TodoDbContext
        :DbContext
    {
        #region Ctor.
        public TodoDbContext()
            : base("name=TodoDbContext")
        {
            //Database.SetInitializer<TodoDbContext>(new CreateDatabaseIfNotExists<TodoDbContext>());
            Configuration.LazyLoadingEnabled = false;
            Database.SetInitializer<TodoDbContext>(new DatabaseInitializer());
            Database.Log += log => Console.WriteLine(log);
        }
        #endregion

        #region Override.
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            //modelBuilder.Configurations.Add(new TodoMap());
            //modelBuilder.Configurations.Add(new TodoExtMap());

            modelBuilder.Configurations.Add(new UserMap());
            modelBuilder.Configurations.Add(new UserInfoMap());
            modelBuilder.Configurations.Add(new NewsMap());
            modelBuilder.Configurations.Add(new TagMap());
            modelBuilder.Configurations.Add(new CategoryMap());
        }
        #endregion

        #region Fields.
        //public virtual DbSet<Todo> Todo { get; set; }

        //public virtual DbSet<TodoExt> TodoExt { get; set; } 

        public virtual DbSet<User> User { get; set; }

        public virtual DbSet<UserInfo> UserInfo { get; set; }
        public virtual DbSet<News> News { get; set; }
        public virtual DbSet<Tag> Tag { get; set; }
        public virtual DbSet<Category> Category { get; set; }
        #endregion
    }
}
